<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Example 8.3: Bounding correlation coefficients</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/cvxbook/Ch08_geometric_probs/html/ex_8_3.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Example 8.3: Bounding correlation coefficients</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Joelle Skaf - 10/09/05</span>
<span class="comment">%</span>
<span class="comment">% Let C be a correlation matrix. Given lower and upper bounds on</span>
<span class="comment">% some of the angles (or correlation coeff.), find the maximum and minimum</span>
<span class="comment">% possible values of rho_14 by solving 2 SDP's</span>
<span class="comment">%           minimize/maximize   rho_14</span>
<span class="comment">%                        s.t.   C &gt;=0</span>
<span class="comment">%                               0.6 &lt;= rho_12 &lt;=  0.9</span>
<span class="comment">%                               0.8 &lt;= rho_13 &lt;=  0.9</span>
<span class="comment">%                               0.5 &lt;= rho_24 &lt;=  0.7</span>
<span class="comment">%                              -0.8 &lt;= rho_34 &lt;= -0.4</span>

n = 4;

<span class="comment">% Upper bound SDP</span>
fprintf(1,<span class="string">'Solving the upper bound SDP ...'</span>);

cvx_begin <span class="string">sdp</span>
    variable <span class="string">C1(n,n)</span> <span class="string">symmetric</span>
    maximize ( C1(1,4) )
    C1 &gt;= 0;
    diag(C1) == ones(n,1);
    C1(1,2) &gt;= 0.6;
    C1(1,2) &lt;= 0.9;
    C1(1,3) &gt;= 0.8;
    C1(1,3) &lt;= 0.9;
    C1(2,4) &gt;= 0.5;
    C1(2,4) &lt;= 0.7;
    C1(3,4) &gt;= -0.8;
    C1(3,4) &lt;= -0.4;
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);

<span class="comment">% Lower bound SDP</span>
fprintf(1,<span class="string">'Solving the lower bound SDP ...'</span>);

cvx_begin <span class="string">sdp</span>
    variable <span class="string">C2(n,n)</span> <span class="string">symmetric</span>
    minimize ( C2(1,4) )
    C2 &gt;= 0;
    diag(C2) == ones(n,1);
    C2(1,2) &gt;= 0.6;
    C2(1,2) &lt;= 0.9;
    C2(1,3) &gt;= 0.8;
    C2(1,3) &lt;= 0.9;
    C2(2,4) &gt;= 0.5;
    C2(2,4) &lt;= 0.7;
    C2(3,4) &gt;= -0.8;
    C2(3,4) &lt;= -0.4;
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);
<span class="comment">% Displaying results</span>
disp(<span class="string">'--------------------------------------------------------------------------------'</span>);
disp([<span class="string">'The minimum and maximum values of rho_14 are: '</span> num2str(C2(1,4)) <span class="string">' and '</span> num2str(C1(1,4))]);
disp(<span class="string">'with corresponding correlation matrices: '</span>);
disp(C2)
disp(C1)
</pre>
<a id="output"></a>
<pre class="codeoutput">
Solving the upper bound SDP ... 
Calling Mosek 9.1.9: 18 variables, 6 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:32:15)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 6               
  Cones                  : 0               
  Scalar variables       : 8               
  Matrix variables       : 1               
  Integer variables      : 0               

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.00    
Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 6               
  Cones                  : 0               
  Scalar variables       : 8               
  Matrix variables       : 1               
  Integer variables      : 0               

Optimizer  - threads                : 8               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 6
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 8                 conic                  : 0               
Optimizer  - Semi-definite variables: 1                 scalarized             : 10              
Factor     - setup time             : 0.00              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 21                after factor           : 21              
Factor     - dense dim.             : 0                 flops                  : 5.29e+02        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   1.0e+00  8.0e-01  5.0e+00  0.00e+00   4.000000000e+00   0.000000000e+00   1.0e+00  0.00  
1   2.2e-01  1.8e-01  6.8e-01  5.68e-01   1.601847865e+00   5.752271707e-01   2.2e-01  0.01  
2   7.2e-02  5.8e-02  1.0e-01  1.20e+00   6.556609770e-01   3.423728347e-01   7.2e-02  0.01  
3   7.0e-03  5.6e-03  2.5e-03  1.50e+00   2.625263863e-01   2.385818161e-01   7.0e-03  0.01  
4   8.2e-05  6.5e-05  3.2e-06  1.05e+00   2.303212228e-01   2.300505955e-01   8.2e-05  0.01  
5   2.5e-06  2.0e-06  1.7e-08  9.99e-01   2.299221058e-01   2.299139040e-01   2.5e-06  0.01  
6   5.3e-08  4.2e-08  5.3e-11  1.00e+00   2.299093602e-01   2.299091858e-01   5.3e-08  0.01  
7   5.8e-09  4.7e-09  1.9e-12  1.00e+00   2.299091122e-01   2.299090929e-01   5.8e-09  0.01  
8   8.5e-10  5.2e-09  1.1e-13  1.00e+00   2.299090875e-01   2.299090847e-01   8.5e-10  0.01  
Optimizer terminated. Time: 0.01    


Interior-point solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: 2.2990908751e-01    nrm: 2e+00    Viol.  con: 7e-10    var: 0e+00    barvar: 0e+00  
  Dual.    obj: 2.2990908467e-01    nrm: 1e+00    Viol.  con: 0e+00    var: 3e-10    barvar: 4e-09  
Optimizer summary
  Optimizer                 -                        time: 0.01    
    Interior-point          - iterations : 8         time: 0.01    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.229909
 
Done! 
Solving the lower bound SDP ... 
Calling Mosek 9.1.9: 18 variables, 6 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:32:15)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 6               
  Cones                  : 0               
  Scalar variables       : 8               
  Matrix variables       : 1               
  Integer variables      : 0               

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.00    
Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 6               
  Cones                  : 0               
  Scalar variables       : 8               
  Matrix variables       : 1               
  Integer variables      : 0               

Optimizer  - threads                : 8               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 6
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 8                 conic                  : 0               
Optimizer  - Semi-definite variables: 1                 scalarized             : 10              
Factor     - setup time             : 0.00              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 21                after factor           : 21              
Factor     - dense dim.             : 0                 flops                  : 5.29e+02        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   1.0e+00  8.0e-01  5.0e+00  0.00e+00   4.000000000e+00   0.000000000e+00   1.0e+00  0.00  
1   2.2e-01  1.8e-01  6.7e-01  5.68e-01   1.623017452e+00   5.938125873e-01   2.2e-01  0.01  
2   5.2e-02  4.2e-02  4.7e-02  1.36e+00   6.610632060e-01   4.381337029e-01   5.2e-02  0.01  
3   5.0e-03  4.0e-03  1.2e-03  1.45e+00   4.138204992e-01   3.969081187e-01   5.0e-03  0.01  
4   1.0e-05  8.3e-06  1.0e-07  1.06e+00   3.928604383e-01   3.928251029e-01   1.0e-05  0.01  
5   3.3e-07  2.6e-07  5.7e-10  1.00e+00   3.928217350e-01   3.928206256e-01   3.3e-07  0.01  
6   3.6e-08  2.9e-08  2.1e-11  1.00e+00   3.928204884e-01   3.928203659e-01   3.6e-08  0.01  
7   1.8e-09  1.1e-09  2.3e-13  1.00e+00   3.928203313e-01   3.928203253e-01   1.8e-09  0.01  
Optimizer terminated. Time: 0.02    


Interior-point solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : OPTIMAL
  Primal.  obj: 3.9282033134e-01    nrm: 1e+00    Viol.  con: 1e-09    var: 9e-11    barvar: 0e+00  
  Dual.    obj: 3.9282032532e-01    nrm: 1e+00    Viol.  con: 0e+00    var: 5e-10    barvar: 9e-10  
Optimizer summary
  Optimizer                 -                        time: 0.02    
    Interior-point          - iterations : 7         time: 0.01    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -0.39282
 
Done! 
--------------------------------------------------------------------------------
The minimum and maximum values of rho_14 are: -0.39282 and 0.22991
with corresponding correlation matrices: 
    1.0000    0.6000    0.8542   -0.3928
    0.6000    1.0000    0.3042    0.5000
    0.8542    0.3042    1.0000   -0.5751
   -0.3928    0.5000   -0.5751    1.0000

    1.0000    0.7447    0.8000    0.2299
    0.7447    1.0000    0.3306    0.6013
    0.8000    0.3306    1.0000   -0.4000
    0.2299    0.6013   -0.4000    1.0000

</pre>
</div>
</body>
</html>